706A - Beru-taxi - CodeForces Solution


brute force geometry implementation *900

Please click on ads to support us..

Python Code:

a,b=[int(i) for i in input().split()]
n=int(input())
s=10**10000
for i in range(n):
    x,y,v=[int(i) for i in input().split()]
    h=a
    f=b
    x,h=max(x,h),min(x,h)
    y,f=max(y,f),min(y,f)
    d=(x-h)**2 +(y-f)**2
    d**=0.5
    t=d/v  
    if t<s:
        s=t
print(round(s,15))

C++ Code:

#include <bits/stdc++.h>
using namespace std;
// #define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end()
typedef long long ll;
#define ump unordered_map<int, int>
#define vi vector<int>
typedef pair<int, int> pii;

// Binary_Search, number_theory, math, basic Graph, STLS, Strings, Bit Masks, two pointers. This should help you solve div2 A and B maybe C depends on problem

void solve() {      
    double x1, y1; cin >> x1 >> y1;
    int n; cin >> n;
    double res = 1e9 * 1.0;
    for(int i = 0; i< n; i++) {
        double x2, y2, v;
        cin >> x2 >> y2 >> v;

        double p1 = (x2-x1), p2 = (y2-y1);
        double ed = sqrt((p1*p1 + p2*p2));

        double ans = ed/v;
        if(res > ans) {
            res = ans;
        }
    }
    printf("%.20f\n", res);
}

int main() {
    solve();
}


Comments

Submit
0 Comments
More Questions

733. Flood Fill
206. Reverse Linked List
83. Remove Duplicates from Sorted List
116. Populating Next Right Pointers in Each Node
145. Binary Tree Postorder Traversal
94. Binary Tree Inorder Traversal
101. Symmetric Tree
77. Combinations
46. Permutations
226. Invert Binary Tree
112. Path Sum
1556A - A Variety of Operations
136. Single Number
169. Majority Element
119. Pascal's Triangle II
409. Longest Palindrome
1574A - Regular Bracket Sequences
1574B - Combinatorics Homework
1567A - Domino Disaster
1593A - Elections
1607A - Linear Keyboard
EQUALCOIN Equal Coins
XOREQN Xor Equation
MAKEPAL Weird Palindrome Making
HILLSEQ Hill Sequence
MAXBRIDGE Maximise the bridges
WLDRPL Wildcard Replacement
1221. Split a String in Balanced Strings
1002. Find Common Characters
1602A - Two Subsequences